package com.example.speeddating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.speeddating.annotaion.LoginUser;
import com.example.speeddating.annotaion.TokenCheck;
import com.example.speeddating.common.BaseResponse;
import com.example.speeddating.common.RespGenerator;
import com.example.speeddating.constants.Constants;
import com.example.speeddating.entity.TokenEntity;
import com.example.speeddating.entity.User;
import com.example.speeddating.service.MatchService;
import com.example.speeddating.service.UserService;
//import jakarta.persistence.Id;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * @author tina
 * @since 2023-07-21 08:00:57
 */
@Slf4j
@RestController
public class MatchController {

    @Autowired
    private MatchService matchService;

    @Autowired
    private UserService userService;

    /**
     * 更新匹配
     * @param user
     * @return
     */
    @TokenCheck(roles = "user")
    @PutMapping("/user/match/update")
    public BaseResponse updateMatchUser(@LoginUser TokenEntity user){
        log.info("id"+ user.getId());
        matchService.updateMatchByUserId(user.getId());
        return RespGenerator.returnOK("更新成功");
    }

    /**
     * 今日牵手次数
     * @return
     */
    @GetMapping("/user/match/num")
    public BaseResponse matchNum(){
       Integer num =  matchService.getMatchNum();
       return RespGenerator.returnOK(num);
    }

    /**
     * 今日剩余匹配次数
     * @param tokenEntity
     * @return
     */
    @TokenCheck(roles = "user")
    @GetMapping("/user/leave/num")
    public BaseResponse leaveNum(@LoginUser TokenEntity tokenEntity){
        Integer num =  matchService.getLeaveNum(tokenEntity.getId());
        return RespGenerator.returnOK(Constants.LENGTH_5 -num);
    }

    @GetMapping("/user/match")
    @TokenCheck(roles = "user")
    public BaseResponse<Page> matchUser(@LoginUser TokenEntity tokenEntity, @RequestParam(value = "pageSize") Integer pageSize, @RequestParam(value = "pageNum") Integer pageNum){
        Page page = userService.CosmatchUsers(tokenEntity.getId(), pageNum, pageSize);
        return RespGenerator.returnOK(page);
    }


}
